package entity

import (
	"time"
)

type Money struct {
	RoleID          int32 `gorm:"type:int;primary_key"`
	ServerID        int32
	Coin            int64
	Income          int64 // 每秒银币收益
	MaxIncome       int64
	IncomeUpdatedAt time.Time
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

//func (Money) TableName() string {
//	return "moneys"
//}

// 计算每秒银币收益
func (m Money) CountIncome() int64 {

	var diff = time.Now().Unix() - m.UpdatedAt.Unix()
	if diff < 0 {
		diff = 0
	}

	return diff * m.Income
}
